<?php

namespace common\logics\article;

use Yii;

/**
 * 基础资讯逻辑模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class BaseArticleLogic extends \common\models\sghome\CmsArticle {

    const SCOPE_HOME = 'home';
    const SCOPE_RSS = 'rss';

    /**
     * @var string
     */
    public $scope = self::SCOPE_HOME;

    /**
     * @var \common\models\sghome\UnionStaffs|null
     */
    public $staff;

    /**
     * @return array
     */
    public function getUnionIds() {
        if (!Yii::$app->user->isGuest) {
            return Yii::$app->user->identity->getUnionIds();
        }
        return [];
    }

    /**
     * @return integer
     */
    public function getUnionId() {
        if (!Yii::$app->user->isGuest) {
            return Yii::$app->user->identity->getUnionId();
        }
        return 0;
    }

    /**
     * @return integer
     */
    public function getIsStaff() {
        if (!Yii::$app->user->isGuest) {
            return !!Yii::$app->user->identity->staff;
        }
        return false;
    }

    /**
     * @return integer
     */
    public function getRootId() {
        if (!Yii::$app->user->isGuest) {
            return Yii::$app->user->identity->getRootId();
        }
        return 0;
    }

    /**
     * @return integer
     */
    public function getCompanyId() {
        if (!Yii::$app->user->isGuest) {
            return Yii::$app->user->identity->getCompanyId();
        }
        return 0;
    }

    /**
     * @return array
     */
    public function getRemoveCategoryIds() {
        return [
            340, 339, 253, 342, 353, 354, 355, 357, 364, 366, 367, 368, 369, 370, 375, 377, 381,
        ];
    }

    /**
     * @return array
     */
    public function getRootCategoryIds() {
        $rootId = $this->getRootId();
        if (!$rootId) {
            return [7, 8, 9, 253, 404];
        }
        if ($rootId == 1) {
            return [5, 7, 8, 9, 253, 404];
        }
        return [5, 7, 8, 9, 253, 404];
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'title',
            'description',
            'thumb',
            'extras',
            'weblink',
        ];
    }

}
